package com.xjc.common;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

import java.io.Serial;
import java.io.Serializable;


/**
 * 基础分页入参
 *
 * @author 肖金财
 */
@Data
@Schema(description = "基础分页对象")
public class BasePageDTO implements Serializable {

    @Serial
    private static final long serialVersionUID = 1148755479907413019L;

    @Schema(description = "当前页码", example = "1")
    private Integer current;

    @Schema(description = "显示条数", example = "10")
    private Integer size;

    @Schema(description = "查询模式 0-普通列表 1-树形数据")
    private Integer queryMode;

    /**
     * 分页limit第一个函数的值
     */
    @Schema(hidden = true)
    private Integer num;

    public Integer getNum() {
        if (current == null || current <= 0) {
            return 0;
        }
        return (current - 1) * getSize();
    }

    public Integer getCurrent() {
        if (current == null || current <= 0) {
            return 1;
        }
        return current;
    }

    public Integer getSize() {
        if (size == null) {
            return 10;
        }
        if (size == -1) {
            return Integer.MAX_VALUE;
        }
        return size;
    }
}
